package fr.umlv.projet.android.subject;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import fr.umlv.projet.android.andex.R;
import fr.umlv.projet.android.parser.jaxb.Node;

public class NodeArrayAdapter extends ArrayAdapter<Node> {

	private final Context context;
	private final List<Node> nodes;

	public NodeArrayAdapter(Context context, int resource,
			int textViewResourceId, List<Node> nodes) {
		super(context, resource, textViewResourceId, nodes);
		this.context = context;
		this.nodes = nodes;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.list_node, parent, false);
		TextView textView = (TextView) rowView.findViewById(R.id.label);
		textView.setText(nodes.get(position).getTitle());
		
		if(nodes.get(position).isAnswered()){
			ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
			imageView.setImageResource(R.drawable.ic_validate);
		}
		return rowView;
	}

}
